package com.rla.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.rla.common.annotation.RepeatSubmit;
import com.rla.common.annotation.Log;
import com.rla.common.core.controller.BaseController;
import com.rla.common.core.domain.PageQuery;
import com.rla.common.core.domain.R;
import com.rla.common.utils.validate.AddGroup;
import com.rla.common.utils.validate.EditGroup;
import com.rla.common.enums.BusinessType;
import com.rla.common.utils.poi.ExcelUtil;
import com.rla.domain.vo.BaseConfigOperatVo;
import com.rla.domain.bo.BaseConfigOperatBo;
import com.rla.service.IBaseConfigOperatService;
import com.rla.common.core.page.TableDataInfo;

/**
 * 参数配置——运营配置
 *
 * @author rla
 * @date 2025-09-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rla/operat")
public class BaseConfigOperatController extends BaseController {

    private final IBaseConfigOperatService iBaseConfigOperatService;

    /**
     * 查询参数配置——运营配置列表
     */
    @GetMapping("/list")
    public TableDataInfo<BaseConfigOperatVo> list(BaseConfigOperatBo bo, PageQuery pageQuery) {
        return iBaseConfigOperatService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出参数配置——运营配置列表
     */
    @Log(title = "参数配置——运营配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BaseConfigOperatBo bo, HttpServletResponse response) {
        List<BaseConfigOperatVo> list = iBaseConfigOperatService.queryList(bo);
        ExcelUtil.exportExcel(list, "参数配置——运营配置", BaseConfigOperatVo.class, response);
    }

    /**
     * 获取参数配置——运营配置详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BaseConfigOperatVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iBaseConfigOperatService.queryById(id));
    }

    /**
     * 新增参数配置——运营配置
     */
    @Log(title = "参数配置——运营配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BaseConfigOperatBo bo) {
        return toAjax(iBaseConfigOperatService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改参数配置——运营配置
     */
    @Log(title = "参数配置——运营配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BaseConfigOperatBo bo) {
        return toAjax(iBaseConfigOperatService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除参数配置——运营配置
     *
     * @param ids 主键串
     */
    @Log(title = "参数配置——运营配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iBaseConfigOperatService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
